{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import myutils\n",
    "\n",
    "model_type = \"rnn\"\n",
    "model = myutils.get_model(model_type = model_type, num_classes = 5)\n",
    "model.eval();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "device = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\n",
    "\n",
    "path2weights = \"./models/weights_\"+model_type+\".pt\"\n",
    " \n",
    "model.load_state_dict(torch.load(path2weights))\n",
    "model.to(device);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "path2vido = \"./data/hmdb51_org/turn/50_FIRST_DATES_turn_h_nm_np1_fr_goo_23.avi\"\n",
    "frames, v_len = myutils.get_frames(path2vido, n_frames=16)\n",
    "len(frames), v_len"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pylab as plt\n",
    "%matplotlib inline\n",
    "\n",
    "plt.figure(figsize=(10,10))\n",
    "for ii,img in enumerate(frames[::4]):\n",
    "    plt.subplot(2,2,ii+1)\n",
    "    plt.imshow(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "imgs_tensor = myutils.transform_frames(frames, model_type)\n",
    "print(imgs_tensor.shape, torch.min(imgs_tensor), torch.max(imgs_tensor))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "with torch.no_grad():\n",
    "    out = model(imgs_tensor.to(device)).cpu()\n",
    "    print(out.shape)\n",
    "    pred = torch.argmax(out).item()\n",
    "    print(pred)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
